package com.academic_system.service.impl;/**
 * @Description:
 */

import com.academic_system.mapper.PartyApplyDao;

import com.academic_system.model.*;
import com.academic_system.service.PartyApplyService;

import com.academic_system.util.Message;
import com.academic_system.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @program: campus_information_portal
 * @description: 党建管理学生申请和老师处理业务实现层
 **/
@Service
public class PartyApplyImpl implements PartyApplyService {
    @Autowired
    private PartyApplyDao partyapplyDao;

    /**
     * @param : StuApply stuApply
     * @Description :学生申请入党
     * @methodName :addApplyParty
     * @returnType :void
     **/

    @Override
    public int addApplyParty(StuApply stuApply) {
        partyapplyDao.addApplyParty(stuApply);
        System.out.println("PartyApplyImpl层已执行");
      /*  int flag = stuApply.getApplyPartyState();
        if (flag == 1) {
            return Message.success();
        } else {
            return Message.fail().add("申请失败", "1201");
        }*/
        return 0;
    }

    /**
     * @param : int stuApplyid, int stateupdate
     * @Description: 老师同意学生入党，通过入党申请表主键id将state改为1
     * @methodName :replyOfStuApplyPartyYse
     * @returnType : void
     **/
    @Override
    public Message replyOfStuApplyPartyYes(int stuApplyid) {
        int flag = partyapplyDao.replyOfStuApplyPartyYes(stuApplyid);//疑问flag为什么返回是1
        System.out.println("-----flag=" + flag);
        if (flag == 1) {
            return Message.success();
        }
        return Message.fail().add("1003", "操作失败");
    }
    /*  @Override
  public void replyOfStuApplyPartyYes(int stuApplyid) {
        partyApplyDao.replyOfStuApplyPartyYes(stuApplyid);

        System.out.println("PartyImpl层同意学生入党申请已执行");
    }*/

    /**
     * @Description: 老师拒绝学生入党，通过入党申请表主键id将state改为2
     * @methodName: replyOfStuApplyPartyDeny
     * @param： int stuApplyid
     * @returnType： void
     **/

    @Override
    public Message replyOfStuApplyPartyDeny(int stuApplyid) {
        int flag = partyapplyDao.replyOfStuApplyPartyDeny(stuApplyid);
        System.out.println("flag迷----：" + flag);//成功执行后flag返回的值是1
        if (flag == 1) {
            System.out.println("PartyImpl层拒绝学生入党申请已执行");
            return Message.success();
        }
        return Message.fail().add("1103", "拒绝操作失败");
    }

    /**
     * @Description :学生查询个人信息，信息显示
     * @methodName： queryPartyMemberInforByParty_member_id
     * @param： int party_member_id
     * @returnType： PartyMember
     **/

    @Override
    public PartyMember queryPartyMemberInforByParty_member_id(int party_member_id) {
        PartyMember partyMember = partyapplyDao.queryPartyMemberInforByParty_member_id(party_member_id);
        return partyMember;
    }

    /**
     * @Description: 学生通过党员账号即学生学号查询个人党员信息
     * @methodName: querypartyMemberByAccount
     * @param: int party_member_account
     * @returnType: PartyMember
     **/
    @Override
    public PartyMember querypartyMemberByAccount(int partyMemberAccount) {
        PartyMember partyMember = partyapplyDao.querypartyMemberByAccount(partyMemberAccount);
        return partyMember;
    }

    /**
     * @param :int party_member_id
     * @Description 学生党员查询个人所在党支部基本信息
     * @methodName queryPartyInforByParty_member_id
     * @returnType: Party
     **/

    @Override
    public Party queryPartyInforByParty_member_id(int party_member_id) {
        Party party = partyapplyDao.queryPartyInforByParty_member_id(party_member_id);
        return party;
    }

    /**
     * @param :int party_member_account
     * @Description 学生党员账号，即学生学号查询个人所在党支部基本信息
     * @methodName queryPartyByPartyMemberAccount
     * @returnType: Party
       **/
    @Override
    public Party queryPartyByPartyMemberAccount(int party_member_account) {
        Party party = partyapplyDao.queryPartyByPartyMemberAccount(party_member_account);
        return party;
    }

    /**
     * @param
     * @Description :通过学生学号查询学生ID
     * @methodName
     * @returnType
     **/
    @Override
    public Integer queryStuIdByStuNum(int stu_num) {
        Integer stuID = partyapplyDao.queryStuIdByStuNum(stu_num);
        System.out.println(stuID + "--------------");
        return stuID;
    }

    /**
     * @param :int partyNum
     * @Description :通过党组织编号查询党组织ID
     * @methodName :queryPartyIdByPartyNum
     * @returnType :int
     **/

    @Override
    public int queryPartyIdByPartyNum(int partyNum) {
        //  Party party=partyApplyDao.
        int partyID = partyapplyDao.queryPartyIdByPartyNum(partyNum);
        System.out.println(partyID + "--------------");
        return partyID;
    }

    @Override
    public List<Party> queryAllPartys() {
        List<Party> list = partyapplyDao.queryAllPartys();
        return list;
    }

    /**
     * @param :int stu_num
     * @Description :通过学生学号修改学生政治面貌信息
     * @methodName :updateStudentPoli
     * @returnType :Msg
     **/

    @Override
    public Msg updateStudentPoli(int stu_num) {
        boolean flag = partyapplyDao.updateStudentPoli(stu_num);
        if (flag == true) {
            return Msg.addData(100, "成功");
        }
        return Msg.fail();
    }

    /**
     * @param
     * @Description:老师查询所有学生的申请入党记录
     * @methodName: queryAllStuApplys
     * @returnType: List<StuApply>
     **/
    @Override
    public Message queryAllStuApplys() {
        List<StuApply> stuApplyList = partyapplyDao.queryAllStuApplys();
        if (stuApplyList.size() > 0) {
            // return Message.success().add("noticeList",stuApplyList);
            return Message.success().add("stuApplyList", stuApplyList);
        }
        return Message.fail().add("1003", "查询失败");
    }

    /**
     * @param :StuApply stuApply
     * @Description :多条件动态sql查询
     * @methodName :queryApplyByConditions
     * @returnType :Message
     **/

    public Message queryApplyByConditions(StuApply stuApply) {
        List<StuApply> stuApplies = partyapplyDao.queryApplyByConditions(stuApply);
        System.out.println("-----条件动态sql查询");
        if (stuApplies.size() > 0) {
            return Message.success().add("StuApplyList", stuApplies);
        }
        return Message.fail().add("1001", "查询失败");
    }

    /**
     * @param :int stu_apply_id
     * @Description :通过学生申请入党id查询对应的StuApply对象
     * @methodName :querystuApplyBystuApplyId
     * @returnType :Message
     **/
    @Override
    public Message querystuApplyBystuApplyId(int stu_apply_id) {
        StuApply stuApply = partyapplyDao.querystuApplyBystuApplyId(stu_apply_id);
        if (stuApply != null) {
            return Message.success().add("stuApply", stuApply);
        }
        return Message.fail().add("1102", "查询失败");
    }

    /**
     * @param :partyMember
     * @Description: 老师点击同意入党的同时往党员表添加一条新的对应记录
     * @methodName: addPartyMember
     * @returnType: Message
     **/

    @Override
    public Message addPartyMember(PartyMember partyMember) {
        int flag = partyapplyDao.addPartyMember(partyMember);
        if (flag == 1) {
            return Message.success();
        }
        return Message.fail().add("1102", "添加党员失败");
    }

    /**
     * @param :stuId
     * @Description 根据学生id查询一个4级成绩
     * @methodName queryCet4
     * @returnType int
     **/

    @Override
    public int queryCet4(int stuId) {
        int cet4 = partyapplyDao.queryCet4(stuId);
        return cet4;
    }

    /**
     * @param :int stuNum
     * @Description :通过学生党员账号即学生学号查看对应党组织政治面貌的统计
     * @methodName :queryPoliTypeByParMemberNum
     * @returnType :List<Map>
     **/
    @Override
    public List<Map> queryPoliTypeByParMemberNum(int stuNum) {
        List<Map> statics = partyapplyDao.queryPoliTypeByParMemberNum(stuNum);
        System.out.println("政治面貌统计：" + statics);
        return statics;
    }

    /**
     * @param : stuId
     * @Description 根据学生id查询一个4级成绩, 根据四级成绩判断是否有资格入党
     * @methodName judgeApplyBycet4
     * @returnType Message
     **/
  /*  @Override
    public Message judgeApplyBycet4(int stuNum) {
        Message m = new Message();
        //首先根据学生学号得到学生Id
        int stuId = partyApplyDao.queryStuIdByStuNum(stuNum);
        //根据学生Id查询学生四级成绩
        int cet4 = partyApplyDao.queryCet4(stuId);
        //如果四级小于425，则学生端提交申请不成功，并提示原因是未过四级
        if(cet4<425){
            Message.fail().add("failApplyReason", "sorry,四级未过，不能提交入党申请");
        }else{

        }
    }*/

}
